//
//  AddAdressController.swift
//  AdressBook
//
//  Created by admin on 16/1/21.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class AddAddressController: UIViewController {
    
    @IBOutlet weak var saveAddressButton: UIBarButtonItem!
    @IBOutlet weak var name: UITextField!
    @IBOutlet weak var address: UITextField!
    weak var addAddressDelegate:AddAddressControllerDelegate!
    // 检测信息是否出入完全
    @IBAction func checkAddressInfo(sender: AnyObject) {
        self.saveAddressButton.enabled = self.name.text != "" && self.address.text != ""
    }
    // 保存数据按钮
    @IBAction func saveAddress(sender: AnyObject) {
        let address = Address(name: self.name.text!, address: self.address.text!)
        self.addAddressDelegate?.saveAddressButtonClicked?(address)
        self.navigationController?.popViewControllerAnimated(true)
    }
}
// 保存数据代理协议
@objc protocol AddAddressControllerDelegate
{
    optional func saveAddressButtonClicked(address:Address)
}